package com.anran.verificationcode.service.impl;


import com.anran.common.module.dto.NumberCodeDTO;
import com.anran.common.response.ResponseResult;
import com.anran.verificationcode.service.NumberCodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class NumberCodeServiceImpl implements NumberCodeService {

    final static Logger logger = LoggerFactory.getLogger(NumberCodeServiceImpl.class);

    @Override
    public ResponseResult<NumberCodeDTO> getNumberCode(int size) {
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10,size-1));
        int resultInt = (int) mathRandom;
        NumberCodeDTO numberCodeResponse = new NumberCodeDTO();
        numberCodeResponse.setNumberCode(resultInt);
        logger.info("验证码:{}",numberCodeResponse);
        return ResponseResult.success(numberCodeResponse);
    }
}
